import jsonschema


def create_custom_schema(types, properties, required=None):
    schema = {
        "type": types,
        "properties": properties
    }
    if required:
        schema["required"] = required
    return schema


def validate_data(data, schema):
    try:
        jsonschema.validate(data, schema)
        print("数据符合预期的 JSON 结构和格式")
    except jsonschema.exceptions.ValidationError as e:
        print("数据与预期不符:", e)


if __name__ == '__main__':
    res = create_custom_schema("object", {"name": {"type": "string"}, "age": {"type": "integer"}, }, ["name", "age"])
    datas = {
        "name": "juns",
        "age": 18
    }
    validate_data(datas, res)
